using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EstimationStudio.Core;

namespace EstimationStudio.Tests
{
    [TestClass]
	public sealed class FormulaTests
	{
        [TestMethod]
		public void ExpectedCase ()
		{
            Assert.AreEqual(1.54, new Formulas().ExpectedCase(1.25, 1.5, 2.0));
		}

        [TestMethod]
		public void Influence ()
		{
			AdjustmentVariability ratings = new AdjustmentVariability(0.73, 0.87, 1.17, 1.34, 1.74);
			Assert.AreEqual(2.38, ratings.Influence);

			ratings = new AdjustmentVariability(1.22, 1.10, 0.88, 0.81, Double.NaN);
			Assert.AreEqual(1.51, ratings.Influence);

			ratings = new AdjustmentVariability(Double.NaN, .95, 1.07, 1.15, 1.24);
			Assert.AreEqual(1.31, ratings.Influence);
		}

        [TestMethod]
		public void ErrorVariability ()
		{
			Estimate estimate = new Estimate();

			Feature feature = new Feature();
			feature.WorstCase = 100.0;
			feature.NominalCase = 100.0;
			feature.BestCase = 100.0;

			estimate.Features.Add(feature);

			ProjectPhase projectPhase = new ProjectPhase();
			projectPhase.ErrorVariability = new ErrorVariability(0.25, 4.0);

			ErrorVariability initialConceptVariability = new Formulas().ErrorVariability(estimate, projectPhase);
			Assert.AreEqual(25.0, initialConceptVariability.Low);
			Assert.AreEqual(400.0, initialConceptVariability.High);

			Feature feature2 = new Feature();
			feature2.WorstCase = 100.0;
			feature2.NominalCase = 100.0;
			feature2.BestCase = 100.0;
			estimate.Features.Add(feature2);

            initialConceptVariability = new Formulas().ErrorVariability(estimate, projectPhase);
			Assert.AreEqual(50.0, initialConceptVariability.Low);
			Assert.AreEqual(800.0, initialConceptVariability.High);
		}

        [TestMethod]
		public void ErrorVariabilityWithAdjustmentFactors ()
		{
			Estimate estimate = new Estimate();

			Feature feature = new Feature();
			feature.WorstCase = 100.0;
			feature.NominalCase = 100.0;
			feature.BestCase = 100.0;
			estimate.Features.Add(feature);

			ProjectPhase projectPhase = new ProjectPhase();
			projectPhase.ErrorVariability = new ErrorVariability(0.25, 4.0);

            ErrorVariability initialConceptVariability = new Formulas().ErrorVariability(estimate, projectPhase);
			Assert.AreEqual(25.0, initialConceptVariability.Low);
			Assert.AreEqual(400.0, initialConceptVariability.High);
		}

        [TestMethod, Ignore]
		public void SimpleStandardDeviationFormula ()
		{
		}

        [TestMethod, Ignore]
		public void ComplexStandardDeviationFormula ()
		{
		}
	}
}